import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'

import axios from 'axios'
axios.defaults.baseURL = 'http://10.96.36.47:573';

import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// 白名单
const publicPages = ['login', 'register']

router.beforeEach(
    async (to, from, next) => {
        if (publicPages.includes(to.name)) {
            // 如果用户访问的是公开的页面
            next()
        }
        else if (localStorage.getItem('token')) {
            // 那如果验证通过则允许导航
            next()
            document.title = to.meta.title
        } else {
            next('/login')
        }
    }
)

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(createPinia())
app.use(router)

app.mount('#app')